#################### GET ALL INCLUDES #############################
idf_build_get_property(all_incs INCLUDE_DIRECTORIES)
set(all_deps freertos bt nvs_flash)
set(watched_deps )
list(LENGTH all_deps new_count)
message(STATUS "count=${new_count}")
WHILE (1)
    set(last_count ${new_count})
    #message(STATUS "current deps=${all_deps}")
    foreach(_var ${all_deps})
        list(FIND watched_deps ${_var} hasdep)
        if (${hasdep} STREQUAL "-1")
            message(STATUS "try to expand ${_var}")
            list(APPEND watched_deps ${_var})
            idf_component_get_property(cpth ${_var} COMPONENT_DIR)
            idf_component_get_property(incs ${_var} INCLUDE_DIRS)
            message(STATUS "${_var} incs=${incs}")
            idf_component_get_property(deps ${_var} REQUIRES)
            message(STATUS "${_var} deps=${deps}")
            foreach(_inc ${incs})
                list(APPEND all_incs ${cpth}/${_inc})
            endforeach()

            foreach(_dep ${deps})
                list(FIND watched_deps ${_dep} hasdep)
                if (${hasdep} STREQUAL "-1")
                    list(APPEND all_deps ${_dep})
                    #message(STATUS "append new ${_dep} to expand")
                endif()
            endforeach()
        endif()
    endforeach()
    list(LENGTH all_deps new_count)
    #message(STATUS "last_count=${last_count}, new_count=${new_count}")
    if (${new_count} STREQUAL ${last_count})
        break()
    endif()
ENDWHILE()
message(STATUS "all deps=${all_deps}")
message(STATUS "all incs=${all_incs}")
#################### GET ALL INCLUDES #############################